# Vaccine Diplomacy

## Replicates tables in appendix

### Note to user: ordered logit models do not report clustered standard errors, these were calculated in Stata. Please see ordered_logit.do to replicate standard errors.

source("table_function.R")
source("LDV_table_function.R")

# Table A1: Survey sample summary statistics ----

## Table made manually, but estimates can be reproduced below

df <- read_dta("baseline_vaccine_wide.dta")

df <- df |> 
  filter(sample_causal == 1) |> 
  mutate(nse1 = case_when(
    ses_survey_all %in% c(121) & country=='Argentina' ~ 'high',
    ses_survey_all %in% c(331, 630, 632) & country=='Argentina' ~ 'middle',
    ses_survey_all %in% c(343) & country=='Argentina' ~ 'low',
    ses_survey_all %in% c(76, 133) & country=='Brasil' ~ 'high',
    ses_survey_all %in% c(458, 602, 791) & country=='Brasil' ~ 'middle',
    ses_survey_all %in% c(818) & country=='Brasil' ~'low',
    ses_survey_all %in% c(32, 152) & country=='Chile' ~ 'high',
    ses_survey_all %in% c(153, 241, 489, 222) & country=='Chile' ~ 'middle',
    ses_survey_all %in% c(625) & country=='Chile' ~ 'low',
    ses_survey_all %in% c(83, 134) & country=='Colombia' ~ 'high',
    ses_survey_all %in% c(231, 2, 580) & country=='Colombia' ~ 'middle',
    ses_survey_all %in% c(662, 320) & country=='Colombia' ~ 'low',
    ses_survey_all %in% c(59, 155, 236) & country=='México' ~ 'high',
    ses_survey_all %in% c(245, 330, 374) & country=='México' ~ 'middle',
    ses_survey_all %in% c(702) & country=='México' ~ 'low',
    ses_survey_all %in% c(24, 87, 19) & country=='Perú' ~ 'high',
    ses_survey_all %in% c(228, 471, 292) & country=='Perú' ~ 'middle',
    ses_survey_all %in% c(467, 613) & country=='Perú' ~ 'low')
  )

df <- df |> 
  mutate(age = as.numeric(age_years),
         gender_rec = case_when(
           gender == 1 ~ 0,
           gender == 2 ~ 1
         ),
         riskfactor = case_when(
           cronic_illness_0 == 1  ~ 0,
           cronic_illness_1 == 1  ~ 1,
           cronic_illness_2 == 1  ~ 1,
           cronic_illness_3 == 1  ~ 1,
           cronic_illness_4 == 1  ~ 1,
           cronic_illness_5 == 1  ~ 1,
           cronic_illness__8 == 1 ~ 1
         ),
         catholic = ifelse(religion == 1, 1, 0),
         edu_none = ifelse(education == "none", 1, 0),
         edu_primary = ifelse(education == "primary", 1, 0),
         edu_secondary = ifelse(education == "secondary", 1, 0),
         edu_higher = ifelse(education == "university", 1, 0),
         edu_otherhigher = ifelse(education == "other_higher", 1, 0),
         ses_low = ifelse(nse1 == "low", 1, 0),
         ses_med = ifelse(nse1 == "middle", 1, 0),
         ses_high = ifelse(nse1 == "high", 1, 0))

vars <- c("age", "gender_rec", "riskfactor", "catholic", "edu_none", "edu_primary", "edu_secondary", "edu_higher", "edu_otherhigher", "ses_low", "ses_med", "ses_high")

baseline_summary_table <- df |> 
  group_by(country) |> 
  dplyr::summarize(across(
    all_of(vars),
    .fns = list(Mean = mean, SD = sd), na.rm = TRUE,
    .names = "{col}_{fn}"))

df_end <- read.csv("vaccine_diplomacy_wide.csv")
df_end <- df_end |> filter(Finished==TRUE)
mergeidend <- df_end$mergeid
df <- df |> mutate(mergeid = substr(ticket, 1, 16))
df <- df |> mutate(recontacted = ifelse(mergeid %in% mergeidend, 1, 0))
df <- df |> filter(recontacted == 1)
    
endline_summary_table <- df |> 
  group_by(country) |> 
  dplyr::summarize(across(
    all_of(vars),
    .fns = list(Mean = mean, SD = sd), na.rm = TRUE,
    .names = "{col}_{fn}"))

rm(baseline_summary_table, df, df_end, endline_summary_table, mergeidend, vars)

# Table A2: Sample means, in comparison with 2021 LAPOP survey and recent census data ----

## Table made manually, but estimates can be reproduced below

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |> 
  mutate(gender_rec = ifelse(gender == 1, 0, 1),
         edu_none = ifelse(education == "none", 1, 0),
         edu_primary = ifelse(education == "primary", 1, 0),
         edu_secondary = ifelse(education == "secondary", 1, 0),
         edu_university = ifelse(education == "university" | education == "other_higher", 1, 0),
         nse_low = ifelse(nse < 3, 1, 0),
         nse_middle = ifelse(nse >= 3 & nse <= 5, 1, 0),
         nse_high = ifelse(nse >=6, 1, 0),
         worse_econ = ifelse(economic_situ_covid < 3, 1, 0),
         covid_serious = ifelse(serious_covid > 3, 1, 0),
         mayor_trust = ifelse(trust_persons_insts_mayor >= 3, 1, 0),
         china_trust = ifelse(trust_china_end_pre >= 3, 1, 0),
         us_trust = ifelse(trust_us_end_pre >= 3, 1, 0))

vaccinated_sample <- diplomacy_wide |> 
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |> 
  filter(!is.na(trust_china_baseline)) # removes missing values and replicates observational sample exactly

vars <- c("Age" = "age",
          "Male" = "gender_rec",
          "Completed no formal education" = "edu_none",
          "Completed primary education" = "edu_primary",
          "Completed secondary education" = "edu_secondary",
          "Completed tertiary education" = "edu_university",
          "Low socioeconomic status"= "nse_low",
          "Medium socioeconomic status" = "nse_middle",
          "High socioeconomic status"= "nse_high",
          "Worse personal economic situation than before COVID-19" = "worse_econ",
          "Believe COVID-19 is somewhat or very serious"= "covid_serious",
          "Some or a lot of trust in mayor or local government" = "mayor_trust",
          "Some or a lot of trust in China"= "china_trust",
          "Some or a lot of trust in US" = "us_trust")

vaccinated_summary_table <- vaccinated_sample |> 
  dplyr::summarize(across(
    all_of(vars),
    .fns = list(Mean = mean), na.rm = TRUE,
    .names = "{col}_{fn}"))

experimental_summary_table <- diplomacy_wide |> 
  filter(!is.na(trust_china_end_post)) |> # removes missing values and replicates experiment sample exactly
  dplyr::summarize(across(
    all_of(vars),
    .fns = list(Mean = mean), na.rm = TRUE,
    .names = "{col}_{fn}"))

summary_table <- bind_cols(t(vaccinated_summary_table), t(experimental_summary_table))

summary_table <- summary_table |> 
  mutate(variable = names(vars)) |> 
  relocate(variable)

names(summary_table) <- c("", "Vaccinated sample", "Experimental sample")

rm(diplomacy_wide, experimental_summary_table, summary_table, vaccinated_sample, vaccinated_summary_table, vars)
  
# Table A3: Vaccine eligibility blocks (by the time of the survey) ----

## Table made manually

# Table A4: Covariate balance across individuals that received vaccines developed in different countries ----

diplomacy_wide <-
  read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  mutate(know_vaccine_country = relevel(factor(know_vaccine_country, levels = c("China", "Russia", "UK", "US")), ref = "US"))

{ pre_treatment_covariates <- c("education_enc",
                              "education_primary",
                              "education_secondary",
                              "education_other",
                              "education_university",
                              "female",
                              "home_conditions_water",
                              "home_conditions_drainage",
                              "home_conditions_electricity",
                              "home_conditions_none",
                              "covid_news",
                              "covid_news_1",
                              "covid_news_2",
                              "covid_news_3",
                              "covid_news_4",
                              "covid_news_5",
                              "covid_news_6",
                              "covid_news_7",
                              "serious_covid",
                              "percent_for_imm_pre_1",
                              "general_hesitancy_1",
                              "general_hesitancy_2",
                              "general_hesitancy_3",
                              "general_hesitancy_4",
                              "general_hesitancy_5",
                              "refused_vaccine",
                              "reasons_hesitancy_side", 
                              "reasons_hesitancy_covid",
                              "reasons_hesitancy_quickly",
                              "reasons_hesitancy_effective",
                              "reasons_hesitancy_risk",
                              "reasons_hesitancy_vaccine",
                              "reasons_hesitancy_naturalimm",
                              "reasons_hesitancy_hadcovid",
                              "reasons_hesitancy_govtrust",
                              "reasons_hesitancy_finance",
                              "reasons_hesitancy_other",
                              "cronic_illness_none",         
                              "cronic_illness_diabetes",     
                              "cronic_illness_cardiovasc",   
                              "cronic_illness_obese",        
                              "cronic_illness_autoimmune",   
                              "cronic_illness_pulmonary",    
                              "cronic_illness__rathernotsay",
                              "had_covid",
                              "know_serious_covid",
                              "economic_situ_covid",
                              "gov_vaccine_priority",
                              "left_right_scale_1",
                              "satisfied_govt_covid_1",
                              "satisfied_govt_covid_2",
                              "satisfied_govt_covid_3",
                              "vote_president",
                              "vote_mayor",
                              "trust_persons_insts_pres",
                              "trust_persons_insts_mayor",
                              "trust_persons_insts_health",
                              "trust_persons_insts_med",
                              "trust_persons_insts_lnews",
                              "trust_persons_insts_rnews",
                              "trust_persons_insts_relig",
                              "trust_orgs_localhealth",
                              "trust_orgs_armed",
                              "trust_orgs_civilsociety",
                              "trust_china_baseline",
                              "trust_trump_baseline",
                              "trust_biden_baseline",
                              "trust_uk_baseline",
                              "trust_russia_baseline",
                              "indoor_contrib_covid",
                              "risk_aversion",
                              "discount_rate",
                              "impt_help_community_share",
                              "impt_respect_comm",
                              "social_influence",
                              "treat_info",      
                              "treat_biden",
                              "treat_herd60",
                              "treat_herd70",
                              "treat_herd80",
                              "treat_herd60_cw",
                              "treat_herd70_cw",
                              "treat_herd80_cw",
                              "treat_motiv_altr",
                              "treat_motiv_econ",
                              "treat_motiv_soci"
) }

balance_rolloutfe <- lapply(1:length(pre_treatment_covariates), function(x)
  lm_robust(as.formula(
    paste0(pre_treatment_covariates[x], " ~ factor(know_vaccine_country)"
    )),
    fixed_effects = rollout_fe,
    se_type = "stata",
    data = diplomacy_wide)
)

balance_rolloutfe_trust <- lapply(1:length(pre_treatment_covariates), function(x)
  lm_robust(as.formula(
    paste0(pre_treatment_covariates[x], " ~ factor(know_vaccine_country) +
           factor(trust_china_baseline) +
           factor(trust_russia_baseline) +
           factor(trust_uk_baseline) +
           factor(trust_biden_baseline)"
    )),
    fixed_effects = rollout_fe,
    se_type = "stata",
    data = diplomacy_wide)
)

balance_rolloutfe <- sapply(1:length(pre_treatment_covariates), function(x)
  tryCatch(
    linearHypothesis(balance_rolloutfe[[x]], c("factor(know_vaccine_country)China = 0",
                                               "factor(know_vaccine_country)Russia = 0",
                                               "factor(know_vaccine_country)UK = 0"),
                     test = "F")$`Pr(>F)`[2],
    error=function(e){cat("ERROR :",conditionMessage(e), "\n")}
  )
)

balance_rolloutfe_trust <- sapply(1:length(pre_treatment_covariates), function(x)
  tryCatch(
    linearHypothesis(balance_rolloutfe_trust[[x]], c("factor(know_vaccine_country)China = 0",
                                                     "factor(know_vaccine_country)Russia = 0",
                                                     "factor(know_vaccine_country)UK = 0"),
                     test = "F")$`Pr(>F)`[2],
    error=function(e){cat("ERROR :",conditionMessage(e), "\n")}
  )
)

balance_rolloutfe <- round(as.numeric(unlist(as.character(balance_rolloutfe))), 3)
balance_rolloutfe_trust <- round(as.numeric(unlist(as.character(balance_rolloutfe_trust))), 3)

{ covariate_labels <- c("Education",
                      "Education - At Least Primary",
                      "Education - At Least Secondary",
                      "Education - At Least Other Higher",
                      "Education - At Least University",
                      "Female",
                      "Running Water in Home",
                      "Sewage in Home",
                      "Electricity in Home",
                      "No Running Water, Sewage, or Electricity in Home",
                      "Baseline COVID News Consumption - Aggregate",
                      "Baseline COVID News Consumption - TV",
                      "Baseline COVID News Consumption - Radio",
                      "Baseline COVID News Consumption - Print",
                      "Baseline COVID News Consumption - Word of Mouth",
                      "Baseline COVID News Consumption - WhatsApp",
                      "Baseline COVID News Consumption - Social Media",
                      "Baseline COVID News Consumption - News Websites",
                      "COVID Severity in Country",
                      "Herd Immunity Prior",
                      "General Vaccine Hesitancy - Protect from Disease",
                      "General Vaccine Hesitancy - Good for Community",
                      "General Vaccine Hesitancy - Trust in Government",
                      "General Vaccine Hesitancy - Follow Doctor Instructions",
                      "General Vaccine Hesitancy - Trust in International Medical Experts",
                      "General Vaccine Hesitancy - Refused Vaccine",
                      "COVID Hesitancy Reasons - Side Effects",
                      "COVID Hesitancy Reasons - Vaccine Gives COVID",
                      "COVID Hesitancy Reasons - Produced Too Quickly",
                      "COVID Hesitancy Reasons - Not Effective",
                      "COVID Hesitancy Reasons - Not At Risk of Getting COVID",
                      "COVID Hesitancy Reasons - Against Vaccines Generally",
                      "COVID Hesitancy Reasons - Prefer 'Natural' Immunity",
                      "COVID Hesitancy Reasons - Already Had COVID",
                      "COVID Hesitancy Reasons - Don't Trust Government",
                      "COVID Hesitancy Reasons - Financial Concerns",
                      "COVID Hesitancy Reasons - Other",
                      "Comorbidities - None",
                      "Comorbidities - Diabetes",
                      "Comorbidities - Cardiovascular Diseases",
                      "Comorbidities - Obesity",
                      "Comorbidities - Autoimmune Diseases",
                      "Comorbidities - Chronic Obstructive Pulmonary Disease",
                      "Comorbidities - Prefer Not To Share",
                      "Had COVID",
                      "Know Someone Seriously Ill or Passed Away COVID",
                      "COVID Economic Situation",
                      "Government Vaccine Priority",
                      "Left/Right Political Scale",
                      "Satisfied with President COVID Management",
                      "Satisfied with Mayor COVID Management",
                      "Satisfied with Health Ministry COVID Management",
                      "Would Vote for Current President",
                      "Would Vote for Current Mayor",
                      "Trust in Current President",
                      "Trust in Current Mayor",
                      "Trust in National Health Ministry",
                      "Trust in National Medical Association",
                      "Trust in Left-Wing Newspaper",
                      "Trust in Right-Wing Newspaper",
                      "Trust in Religious Leader",
                      "Trust in Local Healthcare",
                      "Trust in Armed Forces",
                      "Trust in Civil Society Organizations",
                      "Trust in Government of China (Baseline)",
                      "Trust in Government of U.S. Under Trump (Baseline)",
                      "Trust in Government of U.S. Under Biden (Baseline)",
                      "Trust in Government of U.K. (Baseline)",
                      "Trust in Government of Russia (Baseline)",
                      "Meeting Indoor With Non-Family Contributes to COVID",
                      "Risk Aversion",
                      "Discount Rate",
                      "Donation Amount",
                      "Important to Receive Respect and Recognition",
                      "Social Influence",
                      "Vaccine Information Treatment",      
                      "Vaccine Information Treatment with Biden Endorsement",     
                      "Vaccine Information Treatment with Expert Herd Immunity Prediction (60%)",    
                      "Vaccine Information Treatment with Expert Herd Immunity Prediction (70%)",
                      "Vaccine Information Treatment with Expert Herd Immunity Prediction (70%)",
                      "Vaccine Information Treatment with Expert Herd Immunity Prediction (60%) and Current Willingness",
                      "Vaccine Information Treatment with Expert Herd Immunity Prediction (70%) and Current Willingness",
                      "Vaccine Information Treatment with Expert Herd Immunity Prediction (80%) and Current Willingness",
                      "Motivation Treatment - Altruism",
                      "Motivation Treatment - Economic Recovery",
                      "Motivation Treatment - Social Approval"
) }

balance_tests <- data.frame(pre_treatment_covariates, balance_rolloutfe, balance_rolloutfe_trust)

balance_tests <- balance_tests |>
  mutate(across(
    starts_with("balance_"),
    ~ case_when(
      . > 0.1 ~ as.character(round(., 3)),
      . <= 0.1 & . > 0.05 ~ paste0(round(., 3), "*"),
      . <= 0.05 & . > 0.01 ~ paste0(round(., 3), "**"),
      . <= 0.01 ~ paste0(round(., 3), "***")
    ))) |>
  mutate(balance_rolloutfe_trust = case_when(
    pre_treatment_covariates == "trust_china_baseline" ~ "",
    pre_treatment_covariates == "trust_biden_baseline" ~ "",
    pre_treatment_covariates == "trust_uk_baseline" ~ "",
    pre_treatment_covariates == "trust_russia_baseline" ~ "",
    pre_treatment_covariates != "trust_china_baseline" | 
      pre_treatment_covariates != "trust_biden_baseline"  |
      pre_treatment_covariates != "trust_uk_baseline"  |
      pre_treatment_covariates != "trust_russia_baseline" ~ balance_rolloutfe_trust
  )) |>
  mutate(pre_treatment_covariates = covariate_labels)

balance_tests$mean <- sapply(pre_treatment_covariates, function(x)
  round(mean(diplomacy_wide[,x], na.rm = TRUE), 2)
)

balance_tests$sd <- sapply(pre_treatment_covariates, function(x)
  round(sd(diplomacy_wide[,x], na.rm = TRUE), 2)
)

balance_tests <- balance_tests |>
  dplyr::select(pre_treatment_covariates, mean, sd, balance_rolloutfe, balance_rolloutfe_trust)

names(balance_tests) <- c("Covariate",
                          "Mean",
                          "SD",
                          "Equality test (p-value)",
                          "Equality test conditional on prior trust (p-value)")

balance_table <- print(xtable(balance_tests, auto = TRUE), include.rownames = FALSE)

write(balance_table, paste0("Tables/balance_observational.tex"))

# Table A5: The effect of receiving a particular vaccine on an individual's trust in the government of the country where the vaccine was developed, by respondent country ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(country_exp != "india")

country_list <- c("Argentina", "Brasil", "Chile", "Colombia", "Mexico", "Peru")

diplomacy_countries <- lapply(country_list, function(x)
  diplomacy_long |>
    filter(country == x)
)

names(diplomacy_countries) <- country_list

outcome_vector <- c(
  "scale" = "",
  "binary" = "_binary"
)

lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_countries[["Argentina"]],
      diplomacy_countries[["Brasil"]],
      diplomacy_countries[["Chile"]],
      diplomacy_countries[["Colombia"]],
      diplomacy_countries[["Mexico"]],
      diplomacy_countries[["Peru"]]
    ),
    outcomes = c(
      "Argentina" = paste0("country_pre_trust",    outcome_vector[x]),
      "Brasil"    = paste0("country_pre_trust",    outcome_vector[x]),
      "Chile"     = paste0("country_pre_trust",    outcome_vector[x]),
      "Colombia"  = paste0("country_pre_trust",    outcome_vector[x]),
      "Mexico"    = paste0("country_pre_trust",    outcome_vector[x]),
      "Peru"      = paste0("country_pre_trust",    outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "know_vax_treatment", 
      "Country developed vaccine" = "know_vax_treatment",
      "Country developed vaccine" = "know_vax_treatment",
      "Country developed vaccine" = "know_vax_treatment",
      "Country developed vaccine" = "know_vax_treatment",
      "Country developed vaccine" = "know_vax_treatment"
    ),
    trust_covariates = c(
      "country_baseline_trust",
      "country_baseline_trust",
      "country_baseline_trust",
      "country_baseline_trust",
      "country_baseline_trust",
      "country_baseline_trust"
    ),
    fixed_effects_name = "rollout_fe",
    table_name = paste0("by_country_results_observational_", names(outcome_vector[x]))
  )
)

# Table A6: The effect of receiving a particular vaccine on an individual’s trust in the government of the country where the vaccine was developed—with population weights ----

## Only rake weights reported in paper

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(country_exp != "india")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1)

weight_names <- c("weight_joint", "weight_rake")

lapply(1:length(outcome_vector), function(i)
  lapply(weight_names, function(j)
    
    table_function(
      data_frames = list(
        diplomacy_long,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide
      ),
      outcomes = c(
        "Trust (Pooled)"        = paste0("country_pre_trust", outcome_vector[i]),
        "Trust (China)"         = paste0("trust_china_end_pre", outcome_vector[i]),
        "Trust (Russia)"        = paste0("trust_russia_end_pre", outcome_vector[i]),
        "Trust (UK)"            = paste0("trust_uk_end_pre", outcome_vector[i]),
        "Trust (US)"            = paste0("trust_us_end_pre", outcome_vector[i])
      ),
      treatments = c(
        "Country developed vaccine" = "know_vax_treatment", 
        "Country developed vaccine" = "know_vaccine_country_china",
        "Country developed vaccine" = "know_vaccine_country_russia",
        "Country developed vaccine" = "know_vaccine_country_uk",
        "Country developed vaccine" = "know_vaccine_country_us"
      ),
      trust_covariates = c(
        "country_baseline_trust",
        "trust_china_baseline",
        "trust_russia_baseline",
        "trust_uk_baseline",
        "trust_biden_baseline"
      ),
      fixed_effects_name = "rollout_fe",
      weights_name = paste0(j),
      table_name = paste0("main_results_observational_", j, "_", names(outcome_vector[i]))
    )
  )
)

# Tables A7-A8: Robustness checks for the effect of receiving a particular vaccine on an individual’s trust in the government of the country where the vaccine was developed, scale and binary outcomes ----

outcome_vector <- c(
  "scale" = "",
  "binary" = "_binary"
)

## Panel A - Developer country x country-eligibility group x region fixed effects ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(country_exp != "india") |>
  filter(!is.na(state_municipality_1))

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(!is.na(state_municipality_1))

robA <- lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_pre_trust", outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_pre", outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_pre", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_pre", outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_pre", outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "know_vax_treatment", 
      "Country developed vaccine" = "know_vaccine_country_china",
      "Country developed vaccine" = "know_vaccine_country_russia",
      "Country developed vaccine" = "know_vaccine_country_uk",
      "Country developed vaccine" = "know_vaccine_country_us"
    ),
    trust_covariates = c(
      "country_baseline_trust",
      "trust_china_baseline",
      "trust_russia_baseline",
      "trust_uk_baseline",
      "trust_biden_baseline"
    ),
    fixed_effects_name = "rollout_region_fe",
    table_name = paste0("robustness_results_observational_panelA_", names(outcome_vector[x])),
    return_object = TRUE
  )
)

## Panel B - Developer country x country-eligibility group x municipality fixed effects ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(country_exp != "india") |>
  filter(!is.na(state_municipality_2))

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(!is.na(state_municipality_2))

robB <- lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_pre_trust", outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_pre", outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_pre", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_pre", outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_pre", outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "know_vax_treatment", 
      "Country developed vaccine" = "know_vaccine_country_china",
      "Country developed vaccine" = "know_vaccine_country_russia",
      "Country developed vaccine" = "know_vaccine_country_uk",
      "Country developed vaccine" = "know_vaccine_country_us"
    ),
    trust_covariates = c(
      "country_baseline_trust",
      "trust_china_baseline",
      "trust_russia_baseline",
      "trust_uk_baseline",
      "trust_biden_baseline"
    ),
    fixed_effects_name = "rollout_muni_fe",
    table_name = paste0("robustness_results_observational_panelB_", names(outcome_vector[x])),
    return_object = TRUE
  )
)

## Panel C - Adjusting for imbalanced covariates ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(country_exp != "india")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1)

imbalanced_covariates_obs <- c("covid_news_7",
                               "percent_for_imm_pre_1",
                               "general_hesitancy_1",
                               "cronic_illness_obese",
                               "cronic_illness_pulmonary",
                               "cronic_illness__rathernotsay",
                               "had_covid",
                               "trust_trump_baseline",
                               "impt_respect_comm",
                               "treat_herd80_cw"
)

robC <- lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_pre_trust", outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_pre", outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_pre", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_pre", outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_pre", outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "know_vax_treatment", 
      "Country developed vaccine" = "know_vaccine_country_china",
      "Country developed vaccine" = "know_vaccine_country_russia",
      "Country developed vaccine" = "know_vaccine_country_uk",
      "Country developed vaccine" = "know_vaccine_country_us"
    ),
    trust_covariates = c(
      "country_baseline_trust",
      "trust_china_baseline",
      "trust_russia_baseline",
      "trust_uk_baseline",
      "trust_biden_baseline"
    ),
    additional_covariates = imbalanced_covariates_obs,
    fixed_effects_name = "rollout_fe",
    table_name = paste0("robustness_results_observational_panelC_", names(outcome_vector[x])),
    return_object = TRUE
  )
)

## Panel D - All pretreatment covariates ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(country_exp != "india")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1)

{ all_pret_covs_obs <- c("education_enc",
                         "education_primary",
                         "education_secondary",
                         "education_other",
                         "education_university",
                         "female",
                         "home_conditions_water",
                         "home_conditions_drainage",
                         "home_conditions_electricity",
                         "home_conditions_none",
                         "covid_news",
                         "covid_news_1",
                         "covid_news_2",
                         "covid_news_3",
                         "covid_news_4",
                         "covid_news_5",
                         "covid_news_6",
                         "covid_news_7",
                         "serious_covid",
                         "percent_for_imm_pre_1",
                         "general_hesitancy_1",
                         "general_hesitancy_2",
                         "general_hesitancy_3",
                         "general_hesitancy_4",
                         "general_hesitancy_5",
                         "refused_vaccine",
                         "reasons_hesitancy_side", 
                         "reasons_hesitancy_covid",
                         "reasons_hesitancy_quickly",
                         "reasons_hesitancy_effective",
                         "reasons_hesitancy_risk",
                         "reasons_hesitancy_vaccine",
                         "reasons_hesitancy_naturalimm",
                         "reasons_hesitancy_hadcovid",
                         "reasons_hesitancy_govtrust",
                         "reasons_hesitancy_finance",
                         "reasons_hesitancy_other",
                         #"cronic_illness_none",  ## collinear      
                         "cronic_illness_diabetes",     
                         "cronic_illness_cardiovasc",   
                         "cronic_illness_obese",        
                         "cronic_illness_autoimmune",   
                         "cronic_illness_pulmonary",    
                         "cronic_illness__rathernotsay",
                         "had_covid",
                         "know_serious_covid",
                         "economic_situ_covid",
                         "gov_vaccine_priority",
                         "left_right_scale_1",
                         "satisfied_govt_covid_1",
                         "satisfied_govt_covid_2",
                         "satisfied_govt_covid_3",
                         "vote_president",
                         "vote_mayor",
                         "trust_persons_insts_pres",
                         "trust_persons_insts_mayor",
                         "trust_persons_insts_health",
                         "trust_persons_insts_med",
                         "trust_persons_insts_lnews",
                         "trust_persons_insts_rnews",
                         "trust_persons_insts_relig",
                         "trust_orgs_localhealth",
                         "trust_orgs_armed",
                         "trust_orgs_civilsociety",
                         "trust_china_baseline",
                         "trust_trump_baseline",
                         "trust_biden_baseline",
                         "trust_uk_baseline",
                         "trust_russia_baseline",
                         "indoor_contrib_covid",
                         "risk_aversion",
                         "discount_rate",
                         "impt_help_community_share",
                         "impt_respect_comm",
                         "social_influence",
                         "treat_info",      
                         "treat_biden",
                         "treat_herd60",
                         "treat_herd70",
                         "treat_herd80",
                         "treat_herd60_cw",
                         "treat_herd70_cw",
                         "treat_herd80_cw",
                         "treat_motiv_altr",
                         "treat_motiv_econ",
                         "treat_motiv_soci"
)
  }

robD <- lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_pre_trust", outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_pre", outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_pre", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_pre", outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_pre", outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "know_vax_treatment", 
      "Country developed vaccine" = "know_vaccine_country_china",
      "Country developed vaccine" = "know_vaccine_country_russia",
      "Country developed vaccine" = "know_vaccine_country_uk",
      "Country developed vaccine" = "know_vaccine_country_us"
    ),
    trust_covariates = c(
      "country_baseline_trust",
      "trust_china_baseline",
      "trust_russia_baseline",
      "trust_uk_baseline",
      "trust_biden_baseline"
    ),
    additional_covariates = all_pret_covs_obs,
    fixed_effects_name = "rollout_fe",
    table_name = paste0("robustness_results_observational_panelD_", names(outcome_vector[x])),
    return_object = TRUE
  )
)

## Panel E - Difference-in-differences estimates including unvaccinated respondents ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |> 
  filter(country_exp != "india")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8")

robE <- lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Change in Trust (Pooled)"        = paste0("trust_diff", outcome_vector[x]),
      "Change in Trust (China)"         = paste0("trust_diff_china", outcome_vector[x]),
      "Change in Trust (Russia)"        = paste0("trust_diff_russia", outcome_vector[x]),
      "Change in Trust (UK)"            = paste0("trust_diff_uk", outcome_vector[x]),
      "Change in Trust (US)"            = paste0("trust_diff_us", outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "know_vax_treatment", 
      "Country developed vaccine" = "know_vaccine_country_china",
      "Country developed vaccine" = "know_vaccine_country_russia",
      "Country developed vaccine" = "know_vaccine_country_uk",
      "Country developed vaccine" = "know_vaccine_country_us"
    ),
    trust_covariates = NULL,
    fixed_effects_name = "rollout_fe",
    table_name = paste0("robustness_results_observational_panelE_", names(outcome_vector[x]))
  )
)

## Panel F - Defining treatment by country of reported vaccine manufacturer ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(country_exp != "india")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1)

robF <- lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_pre_trust", outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_pre", outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_pre", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_pre", outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_pre", outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "vax_treatment", 
      "Country developed vaccine" = "vaccine_country_china",
      "Country developed vaccine" = "vaccine_country_russia",
      "Country developed vaccine" = "vaccine_country_uk",
      "Country developed vaccine" = "vaccine_country_us"
    ),
    trust_covariates = c(
      "country_baseline_trust",
      "trust_china_baseline",
      "trust_russia_baseline",
      "trust_uk_baseline",
      "trust_biden_baseline"
    ),
    fixed_effects_name = "rollout_fe",
    table_name = paste0("robustness_results_observational_panelF_", names(outcome_vector[x])),
    return_object = TRUE
  )
)

## Panel G - Dropping respondents where perception and manufacturer country disagree ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(vaccine_origin_correct_china     == 1 |
           vaccine_origin_correct_russia  == 1 |
           vaccine_origin_correct_uk      == 1 |
           vaccine_origin_correct_us      == 1) |>
  filter(country_exp != "india")

diplomacy_wide <-
  read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(vaccine_origin_correct_china == 1 |
           vaccine_origin_correct_russia == 1 |
           vaccine_origin_correct_uk == 1 |
           vaccine_origin_correct_us == 1)

robG <- lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_pre_trust", outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_pre", outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_pre", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_pre", outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_pre", outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "know_vax_treatment", 
      "Country developed vaccine" = "know_vaccine_country_china",
      "Country developed vaccine" = "know_vaccine_country_russia",
      "Country developed vaccine" = "know_vaccine_country_uk",
      "Country developed vaccine" = "know_vaccine_country_us"
    ),
    trust_covariates = c(
      "country_baseline_trust",
      "trust_china_baseline",
      "trust_russia_baseline",
      "trust_uk_baseline",
      "trust_biden_baseline"
    ),
    fixed_effects_name = "rollout_fe",
    table_name = paste0("robustness_results_observational_panelG_", names(outcome_vector[x])),
    return_object = TRUE
  )
)

## Panel H - Dropping respondents who answered "don't know" ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1) |>
  filter(country_exp != "india")

diplomacy_wide <-
  read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(know_vaccine_country_china == 1 |
           know_vaccine_country_russia == 1 |
           know_vaccine_country_uk == 1 |
           know_vaccine_country_us == 1)

robH <- lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_pre_trust_missing", outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_pre_missing", outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_pre", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_pre_missing", outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_pre_missing", outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "know_vax_treatment", 
      "Country developed vaccine" = "know_vaccine_country_china",
      "Country developed vaccine" = "know_vaccine_country_russia",
      "Country developed vaccine" = "know_vaccine_country_uk",
      "Country developed vaccine" = "know_vaccine_country_us"
    ),
    trust_covariates = c(
      "country_baseline_trust",
      "trust_china_baseline",
      "trust_russia_baseline",
      "trust_uk_baseline",
      "trust_biden_baseline"
    ),
    fixed_effects_name = "rollout_fe",
    table_name = paste0("robustness_results_observational_panelH_", names(outcome_vector[x])),
    return_object = TRUE
  )
)

## Panel I - Ordered logit and logit estimation ----
### Use ordered_logit.do to replicate standard errors

outcome_vector <- c(
  "ologit" = "",
  "logit" = "_binary"
)

robI <- lapply(1:length(outcome_vector), function(x)
  
  LDV_table_function(
    model = names(outcome_vector[x]),
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_pre_trust",    outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_pre",  outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_pre", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_pre",     outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_pre",     outcome_vector[x])
    ),
    treatments = c(
      "Country developed vaccine" = "know_vax_treatment", 
      "Country developed vaccine" = "know_vaccine_country_china",
      "Country developed vaccine" = "know_vaccine_country_russia",
      "Country developed vaccine" = "know_vaccine_country_uk",
      "Country developed vaccine" = "know_vaccine_country_us"
    ),
    trust_covariates = c(
      "country_baseline_trust",
      "trust_china_baseline",
      "trust_russia_baseline",
      "trust_uk_baseline",
      "trust_biden_baseline"
    ),
    fixed_effects_name = "rollout_fe",
    table_name = paste0("robustness_results_observational_panelI_", names(outcome_vector[x])),
    return_object = TRUE
  )
)

# Table A9: Covariate balance across treated and control individuals ----

diplomacy_wide <-
  read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(reached_country_post_trust == 1)

pre_treatment_covariates <- c("received_vaccine",
                              "know_vaccine_country_china",
                              "know_vaccine_country_india",
                              "know_vaccine_country_russia",
                              "know_vaccine_country_uk",
                              "know_vaccine_country_us",
                              "pret_covid_news_end",
                              "pret_COVID_news_end_tv",
                              "pret_COVID_news_end_radio",
                              "pret_COVID_news_end_newspaper",
                              "pret_COVID_news_end_convo",
                              "pret_COVID_news_end_whatsapp",
                              "pret_COVID_news_end_social",
                              "pret_COVID_news_end_newssite",
                              "pret_vax_pos_info_end",
                              "pret_vax_neg_info_end",
                              "pret_vax_enc_others_end",
                              pre_treatment_covariates)

trust_covariates_wide <- c("trust_china_end_pre",
                           "trust_india_end_pre",
                           "trust_russia_end_pre",
                           "trust_uk_end_pre",
                           "trust_us_end_pre")

balance_wide <- lapply(1:length(pre_treatment_covariates), function(x)
  lm_robust(as.formula(
    paste0(pre_treatment_covariates[x], " ~ treat_rank + ", 
           paste(trust_covariates_wide, collapse = " + "))
  ),
  fixed_effects = exp_block,
  clusters = mergeid,
  se_type = "stata",
  data = diplomacy_wide)
)

balance_wide_trust <- lapply(1:length(pre_treatment_covariates), function(x)
  lm_robust(as.formula(
    paste0(pre_treatment_covariates[x], " ~ treat_rank +
           factor(trust_china_end_pre) +
           factor(trust_india_end_pre) +
           factor(trust_russia_end_pre) +
           factor(trust_uk_end_pre) +
           factor(trust_us_end_pre)"
    )),
    fixed_effects = rollout_fe,
    se_type = "stata",
    data = diplomacy_wide))

balance_wide <- as.character(
  sapply(1:length(pre_treatment_covariates), function(x)
    tryCatch(
      linearHypothesis(balance_wide[[x]], c("treat_rank = 0"), test = "F")$`Pr(>F)`[2],
      error=function(e){cat("ERROR :",conditionMessage(e), "\n")}
    )
  )
)

balance_wide_trust <- as.character(
  sapply(1:length(pre_treatment_covariates), function(x)
    tryCatch(
      linearHypothesis(balance_wide_trust[[x]], c("treat_rank = 0"), test = "F")$`Pr(>F)`[2],
      error=function(e){cat("ERROR :",conditionMessage(e), "\n")}
    )
  )
)

covariate_labels <- c("Received COVID-19 Vaccine",
                      "Received Chinese COVID-19 Vaccine",
                      "Received Indian COVID-19 Vaccine",
                      "Received Russian COVID-19 Vaccine",
                      "Received UK COVID-19 Vaccine",
                      "Received US COVID-19 Vaccine",
                      "Endline COVID News Consumption - Aggregate",
                      "Endline COVID News Consumption - TV",
                      "Endline COVID News Consumption - Radio",
                      "Endline COVID News Consumption - Print",
                      "Endline COVID News Consumption - Word of Mouth",
                      "Endline COVID News Consumption - WhatsApp",
                      "Endline COVID News Consumption - Social Media",
                      "Endline COVID News Consumption - News Websites",
                      "COVID Vaccine Talked About Benefits",
                      "COVID Vaccine Talked About Side Effects",
                      "COVID Vaccine Encouraged Others", 
                      covariate_labels)

balance_tests <- data.frame(pre_treatment_covariates, balance_wide, balance_wide_trust)

balance_tests <- balance_tests |>
  mutate(pre_treatment_covariates = covariate_labels) |>
  # filter(balance_wide != "NULL") |>
  mutate(balance_wide = as.numeric(balance_wide),
         balance_wide_trust = as.numeric(balance_wide_trust)) |>
  mutate(across(
    starts_with("balance_"),
    ~ case_when(
      . > 0.1 ~ as.character(round(., 3)),
      . <= 0.1 & . > 0.05 ~ paste0(round(., 3), "*"),
      . <= 0.05 & . > 0.01 ~ paste0(round(., 3), "**"),
      . <= 0.01 ~ paste0(round(., 3), "***")
    ))) |>
  mutate(balance_wide = case_when(
    pre_treatment_covariates == "received_vaccine" ~ "",
    pre_treatment_covariates == "pret_vax_pos_info_end" ~ "",
    pre_treatment_covariates != "trust_china_baseline" | 
      pre_treatment_covariates != "received_vaccine" ~ balance_wide
  )) |>
  mutate(balance_wide_trust = case_when(
    pre_treatment_covariates == "received_vaccine" ~ "",
    pre_treatment_covariates == "pret_vax_pos_info_end" ~ "",
    pre_treatment_covariates != "trust_china_baseline" | 
      pre_treatment_covariates != "received_vaccine" ~ balance_wide_trust
  ))

balance_tests$mean <- sapply(pre_treatment_covariates, function(x)
  round(mean(diplomacy_wide[,x], na.rm = TRUE), 3)
)

balance_tests$sd <- sapply(pre_treatment_covariates, function(x)
  round(sd(diplomacy_wide[,x], na.rm = TRUE), 3)
)

balance_tests <- balance_tests |>
  dplyr::select(c(pre_treatment_covariates, mean, sd, balance_wide, balance_wide_trust))

names(balance_tests) <- c("Covariate",
                          "Mean",
                          "SD",
                          "Equality test (p-value)",
                          "Equality test conditional on prior trust (p-value)")

balance_table <- print(xtable(balance_tests, auto = TRUE), include.rownames = FALSE)

write(balance_table, paste0("Tables/balance_experimental.tex"))

# Table A10-A11: The effect of aggregate vaccine distribution information treatment on trust in foreign governments, by respondent country (scale and binary, respectively) ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8")

country_list <- c("Argentina", "Brasil", "Chile", "Colombia", "Mexico", "Peru")

diplomacy_countries <- lapply(country_list, function(x)
  diplomacy_long |>
    filter(country == x)
)

names(diplomacy_countries) <- country_list

outcome_vector <- c(
  "scale" = "",
  "binary" = "_binary"
)

lapply(1:length(outcome_vector), function(x)
  
  ## Panel A: Average Treatment Effect ----
  
  table_function(
    data_frames = list(
      diplomacy_countries[["Argentina"]],
      diplomacy_countries[["Brasil"]],
      diplomacy_countries[["Chile"]],
      diplomacy_countries[["Colombia"]],
      diplomacy_countries[["Mexico"]],
      diplomacy_countries[["Peru"]]
    ),
    outcomes = c(
      "Argentina" = paste0("country_post_trust", outcome_vector[x]),
      "Brasil"    = paste0("country_post_trust", outcome_vector[x]),
      "Chile"     = paste0("country_post_trust", outcome_vector[x]),
      "Colombia"  = paste0("country_post_trust", outcome_vector[x]),
      "Mexico"    = paste0("country_post_trust", outcome_vector[x]),
      "Peru"      = paste0("country_post_trust", outcome_vector[x])
    ),
    treatments = c(
      "Treated" = "treat_rank", 
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank"
    ),
    trust_covariates = c(
      "country_pre_trust",
      "country_pre_trust",
      "country_pre_trust",
      "country_pre_trust",
      "country_pre_trust",
      "country_pre_trust"
    ),
    fixed_effects_name = "exp_block",
    table_name = paste0("by_country_results_experimental_ATE_", names(outcome_vector[x]))
  )
)

## Panels B-D ----

het_effects_list <- list(c("rev_rank_reported_ties",
                           "rev_rank_reported_ties",
                           "rev_rank_reported_ties",
                           "rev_rank_reported_ties",
                           "rev_rank_reported_ties",
                           "rev_rank_reported_ties"),
                         c("percentage_reported",
                           "percentage_reported",
                           "percentage_reported",
                           "percentage_reported",
                           "percentage_reported",
                           "percentage_reported"),
                         c("actual_gte_prior",
                           "actual_gte_prior",
                           "actual_gte_prior",
                           "actual_gte_prior",
                           "actual_gte_prior",
                           "actual_gte_prior"))

names(het_effects_list) <- c("rank", "share", "actgteprior")

het_effects_list_names <- list("Reversed rank", "Share", "Reversed rank $\\geq$ Reversed prior")

lapply(1:length(outcome_vector), function(i)
  lapply(1:length(het_effects_list), function(j)
    
    table_function(
      data_frames = list(
        diplomacy_countries[["Argentina"]],
        diplomacy_countries[["Brasil"]],
        diplomacy_countries[["Chile"]],
        diplomacy_countries[["Colombia"]],
        diplomacy_countries[["Mexico"]],
        diplomacy_countries[["Peru"]]
      ),
      outcomes = c(
        "Argentina" = paste0("country_post_trust", outcome_vector[i]),
        "Brasil"    = paste0("country_post_trust", outcome_vector[i]),
        "Chile"     = paste0("country_post_trust", outcome_vector[i]),
        "Colombia"  = paste0("country_post_trust", outcome_vector[i]),
        "Mexico"    = paste0("country_post_trust", outcome_vector[i]),
        "Peru"      = paste0("country_post_trust", outcome_vector[i])
      ),
      treatments = c(
        "Treated" = "treat_rank", 
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank"
      ),
      trust_covariates = c(
        "country_pre_trust",
        "country_pre_trust",
        "country_pre_trust",
        "country_pre_trust",
        "country_pre_trust",
        "country_pre_trust"
      ),
      interaction_effects = list(het_effects_list[[j]]),
      interaction_effects_name = list(het_effects_list_names[[j]]),
      fixed_effects_name = "exp_block",
      table_name = paste0("by_country_results_experimental_", names(het_effects_list)[j], "_", names(outcome_vector[i]))
    )
  )
)

lapply(1:length(outcome_vector), function(x)
  
  ## Panel E: Heterogeneity by rank of vaccines received by the respondent's country and prior beliefs ----
  
  table_function(
    data_frames = list(
      diplomacy_countries[["Argentina"]],
      diplomacy_countries[["Brasil"]],
      diplomacy_countries[["Chile"]],
      diplomacy_countries[["Colombia"]],
      diplomacy_countries[["Mexico"]],
      diplomacy_countries[["Peru"]]
    ),
    outcomes = c(
      "Argentina" = paste0("country_post_trust", outcome_vector[x]),
      "Brasil"    = paste0("country_post_trust", outcome_vector[x]),
      "Chile"     = paste0("country_post_trust", outcome_vector[x]),
      "Colombia"  = paste0("country_post_trust", outcome_vector[x]),
      "Mexico"    = paste0("country_post_trust", outcome_vector[x]),
      "Peru"      = paste0("country_post_trust", outcome_vector[x])
    ),
    treatments = c(
      "Treated" = "treat_rank", 
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank"
    ),
    trust_covariates = c(
      "country_pre_trust",
      "country_pre_trust",
      "country_pre_trust",
      "country_pre_trust",
      "country_pre_trust",
      "country_pre_trust"
    ),
    interaction_effects = list(
      c("rev_rank_reported_ties",
        "rev_rank_reported_ties",
        "rev_rank_reported_ties",
        "rev_rank_reported_ties",
        "rev_rank_reported_ties",
        "rev_rank_reported_ties"),
      c("rev_rank_prior",
        "rev_rank_prior",
        "rev_rank_prior",
        "rev_rank_prior",
        "rev_rank_prior",
        "rev_rank_prior")  
    ),
    interaction_effects_name = list("Reversed Rank", "Reversed prior"),
    fixed_effects_name = "exp_block",
    table_name = paste0("by_country_results_experimental_rankprior_", names(outcome_vector[x]))
  )
)

# Table A12-13:  Effect of aggregate vaccine distribution information treatment on trust in foreign governments, robustness tests for specifications pooled all foreign governments, binary and outcome scale ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8")

outcome_vector <- c(
  "scale" = "",
  "binary" = "_binary"
)

## Column 1: Adjusting for imbalanced covariates ----

imbalanced_covariates_exp <- c("pret_COVID_news_end_radio",
                               "pret_vax_neg_info_end",
                               "covid_news_6",
                               "serious_covid",
                               "reasons_hesitancy_govtrust",
                               "cronic_illness_cardiovasc",
                               "gov_vaccine_priority",
                               "treat_motiv_altr"
)

### Panel A: Average Treatment Effect ----

lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[x]),
      "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[x])
    ),
    treatments = c(
      "Treated" = "treat_rank", 
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank"
    ),
    trust_covariates = c(
      "country_pre_trust",
      "trust_china_end_pre",
      "trust_india_end_pre",
      "trust_russia_end_pre",
      "trust_uk_end_pre",
      "trust_us_end_pre"
    ),
    additional_covariates = imbalanced_covariates_exp,
    fixed_effects_name = "exp_block",
    table_name = paste0("controls_results_experimental_ATE_", names(outcome_vector[x]))
  )
)

### Panels B-D ----

het_effects_list <- list(c("rev_rank_reported_ties",
                           "rev_rank_doses_ties_china",
                           "rev_rank_doses_ties_india",
                           "rev_rank_doses_ties_russia",
                           "rev_rank_doses_ties_uk",
                           "rev_rank_doses_ties_us"),
                         c("percentage_reported",
                           "vax_china",
                           "vax_india",
                           "vax_russia",
                           "vax_uk",
                           "vax_us"),
                         c("actual_gte_prior",
                           "actual_gte_prior_china",
                           "actual_gte_prior_india",
                           "actual_gte_prior_russia",
                           "actual_gte_prior_uk",
                           "actual_gte_prior_us"))

names(het_effects_list) <- c("rank", "share", "actgteprior")

het_effects_list_names <- list("Reversed rank", "Share", "Reversed rank $\\geq$ Reversed prior")

lapply(1:length(outcome_vector), function(i)
  lapply(1:length(het_effects_list), function(j)
    
    table_function(
      data_frames = list(
        diplomacy_long,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide
      ),
      outcomes = c(
        "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[i]),
        "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[i]),
        "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[i]),
        "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[i]),
        "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[i]),
        "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[i])
      ),
      treatments = c(
        "Treated" = "treat_rank", 
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank"
      ),
      trust_covariates = c(
        "country_pre_trust",
        "trust_china_end_pre",
        "trust_india_end_pre",
        "trust_russia_end_pre",
        "trust_uk_end_pre",
        "trust_us_end_pre"
      ),
      additional_covariates = imbalanced_covariates_exp,
      interaction_effects = list(het_effects_list[[j]]),
      interaction_effects_name = list(het_effects_list_names[[j]]),
      fixed_effects_name = "exp_block",
      table_name = paste0("controls_results_experimental_", names(het_effects_list)[j], "_", names(outcome_vector[i]))
    )
  )
)

### Panel E: Heterogeneity by rank of vaccines received by the respondent's country and prior beliefs ----

lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[x]),
      "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[x])
    ),
    treatments = c(
      "Treated" = "treat_rank", 
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank"
    ),
    trust_covariates = c(
      "country_pre_trust",
      "trust_china_end_pre",
      "trust_india_end_pre",
      "trust_russia_end_pre",
      "trust_uk_end_pre",
      "trust_us_end_pre"
    ),
    interaction_effects = list(
      c("rev_rank_reported_ties",
        "rev_rank_doses_ties_china",
        "rev_rank_doses_ties_india",
        "rev_rank_doses_ties_russia",
        "rev_rank_doses_ties_uk",
        "rev_rank_doses_ties_us"),
      c("rev_rank_prior",
        "rev_prior_beliefs_china",
        "rev_prior_beliefs_india",
        "rev_prior_beliefs_russia",
        "rev_prior_beliefs_uk",
        "rev_prior_beliefs_us")  
    ),
    additional_covariates = imbalanced_covariates_exp,
    interaction_effects_name = list("Reversed Rank", "Reversed prior"),
    fixed_effects_name = "exp_block",
    table_name = paste0("controls_results_experimental_rankprior_", names(outcome_vector[x]))
  )
)

## Column 2: Excluding non-unique rankings ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8") |>
  filter(unique_rankings == TRUE)

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8") |>
  filter(unique_rankings == TRUE)

outcome_vector <- c(
  "scale" = "",
  "binary" = "_binary"
)

### Panel A: Average Treatment Effect ----

lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[x]),
      "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[x])
    ),
    treatments = c(
      "Treated" = "treat_rank", 
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank"
    ),
    trust_covariates = c(
      "country_pre_trust",
      "trust_china_end_pre",
      "trust_india_end_pre",
      "trust_russia_end_pre",
      "trust_uk_end_pre",
      "trust_us_end_pre"
    ),
    fixed_effects_name = "exp_block",
    table_name = paste0("experiment_uniquerankings_ATE_", names(outcome_vector[x]))
  )
)

### Panels B-D ----

het_effects_list <- list(c("rev_rank_reported_ties",
                           "rev_rank_doses_ties_china",
                           "rev_rank_doses_ties_india",
                           "rev_rank_doses_ties_russia",
                           "rev_rank_doses_ties_uk",
                           "rev_rank_doses_ties_us"),
                         c("percentage_reported",
                           "vax_china",
                           "vax_india",
                           "vax_russia",
                           "vax_uk",
                           "vax_us"),
                         c("actual_gte_prior",
                           "actual_gte_prior_china",
                           "actual_gte_prior_india",
                           "actual_gte_prior_russia",
                           "actual_gte_prior_uk",
                           "actual_gte_prior_us"))

names(het_effects_list) <- c("rank", "share", "actgteprior")

het_effects_list_names <- list("Reversed rank", "Share", "Reversed rank $\\geq$ Reversed prior")

lapply(1:length(outcome_vector), function(i)
  lapply(1:length(het_effects_list), function(j)
    
    table_function(
      data_frames = list(
        diplomacy_long,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide
      ),
      outcomes = c(
        "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[i]),
        "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[i]),
        "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[i]),
        "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[i]),
        "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[i]),
        "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[i])
      ),
      treatments = c(
        "Treated" = "treat_rank", 
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank"
      ),
      trust_covariates = c(
        "country_pre_trust",
        "trust_china_end_pre",
        "trust_india_end_pre",
        "trust_russia_end_pre",
        "trust_uk_end_pre",
        "trust_us_end_pre"
      ),
      interaction_effects = list(het_effects_list[[j]]),
      interaction_effects_name = list(het_effects_list_names[[j]]),
      fixed_effects_name = "exp_block",
      table_name = paste0("experiment_uniquerankings_", names(het_effects_list)[j], "_", names(outcome_vector[i]))
    )
  )
)

### Panel E: Heterogeneity by rank of vaccines received by the respondent's country and prior beliefs ----

lapply(1:length(outcome_vector), function(x)
  
  table_function(
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[x]),
      "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[x])
    ),
    treatments = c(
      "Treated" = "treat_rank", 
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank"
    ),
    trust_covariates = c(
      "country_pre_trust",
      "trust_china_end_pre",
      "trust_india_end_pre",
      "trust_russia_end_pre",
      "trust_uk_end_pre",
      "trust_us_end_pre"
    ),
    interaction_effects = list(
      c("rev_rank_reported_ties",
        "rev_rank_doses_ties_china",
        "rev_rank_doses_ties_india",
        "rev_rank_doses_ties_russia",
        "rev_rank_doses_ties_uk",
        "rev_rank_doses_ties_us"),
      c("rev_rank_prior",
        "rev_prior_beliefs_china",
        "rev_prior_beliefs_india",
        "rev_prior_beliefs_russia",
        "rev_prior_beliefs_uk",
        "rev_prior_beliefs_us")  
    ),
    interaction_effects_name = list("Reversed Rank", "Reversed prior"),
    fixed_effects_name = "exp_block",
    table_name = paste0("experiment_uniquerankings_rankprior_", names(outcome_vector[x]))
  )
)

## Column 3: Ordered logit and logit estimation ----
### Use ordered_logit.do to replicate standard errors

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8")

### Panel A: Average treatment effect ----

outcome_vector <- c(
  "ologit" = "",
  "logit" = "_binary"
)

lapply(1:length(outcome_vector), function(x)
  
  LDV_table_function(
    model = names(outcome_vector[x]),
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[x]),
      "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[x])
    ),
    treatments = c(
      "Treated" = "treat_rank", 
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank"
    ),
    trust_covariates = c(
      "country_pre_trust",
      "trust_china_end_pre",
      "trust_india_end_pre",
      "trust_russia_end_pre",
      "trust_uk_end_pre",
      "trust_us_end_pre"
    ),
    fixed_effects_name = "exp_block",
    table_name = paste0("experiment_ATE_", names(outcome_vector[x]))
  )
)

### Panels B-D ----

het_effects_list <- list(c("rev_rank_reported_ties",
                           "rev_rank_doses_ties_china",
                           "rev_rank_doses_ties_india",
                           "rev_rank_doses_ties_russia",
                           "rev_rank_doses_ties_uk",
                           "rev_rank_doses_ties_us"),
                         c("percentage_reported",
                           "vax_china",
                           "vax_india",
                           "vax_russia",
                           "vax_uk",
                           "vax_us"),
                         c("actual_gte_prior",
                           "actual_gte_prior_china",
                           "actual_gte_prior_india",
                           "actual_gte_prior_russia",
                           "actual_gte_prior_uk",
                           "actual_gte_prior_us"))

names(het_effects_list) <- c("rank", "share", "actgteprior")

het_effects_list_names <- list("Reversed rank", "Share", "Reversed rank $\\geq$ Reversed prior")

lapply(1:length(outcome_vector), function(i)
  lapply(1:length(het_effects_list), function(j)
    
    LDV_table_function(
      model = names(outcome_vector[i]),
      data_frames = list(
        diplomacy_long,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide
      ),
      outcomes = c(
        "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[i]),
        "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[i]),
        "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[i]),
        "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[i]),
        "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[i]),
        "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[i])
      ),
      treatments = c(
        "Treated" = "treat_rank", 
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank"
      ),
      trust_covariates = c(
        "country_pre_trust",
        "trust_china_end_pre",
        "trust_india_end_pre",
        "trust_russia_end_pre",
        "trust_uk_end_pre",
        "trust_us_end_pre"
      ),
      interaction_effects = list(het_effects_list[[j]]),
      interaction_effects_name = list(het_effects_list_names[[j]]),
      fixed_effects_name = "exp_block",
      table_name = paste0("experiment_", names(het_effects_list)[j], "_", names(outcome_vector[i]))
    )
  )
)

### Panel E: Heterogeneity by rank of vaccines received by the respondent's country and prior beliefs ----

lapply(1:length(outcome_vector), function(x)
  
  LDV_table_function(
    model = names(outcome_vector[x]),
    data_frames = list(
      diplomacy_long,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide,
      diplomacy_wide
    ),
    outcomes = c(
      "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[x]),
      "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[x]),
      "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[x]),
      "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[x]),
      "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[x]),
      "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[x])
    ),
    treatments = c(
      "Treated" = "treat_rank", 
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank",
      "Treated" = "treat_rank"
    ),
    trust_covariates = c(
      "country_pre_trust",
      "trust_china_end_pre",
      "trust_india_end_pre",
      "trust_russia_end_pre",
      "trust_uk_end_pre",
      "trust_us_end_pre"
    ),
    interaction_effects = list(
      c("rev_rank_reported_ties",
        "rev_rank_doses_ties_china",
        "rev_rank_doses_ties_india",
        "rev_rank_doses_ties_russia",
        "rev_rank_doses_ties_uk",
        "rev_rank_doses_ties_us"),
      c("rev_rank_prior",
        "rev_prior_beliefs_china",
        "rev_prior_beliefs_india",
        "rev_prior_beliefs_russia",
        "rev_prior_beliefs_uk",
        "rev_prior_beliefs_us")  
    ),
    interaction_effects_name = list("Reversed Rank", "Reversed prior"),
    fixed_effects_name = "exp_block",
    table_name = paste0("experiment_rankprior_", names(outcome_vector[x]))
  )
)

## Column 4: Population weights ----

diplomacy_long <-
  read.csv("vaccine_diplomacy_long.csv", encoding = "UTF-8")

diplomacy_wide <- read.csv("vaccine_diplomacy_wide.csv", encoding = "UTF-8")

weight_names <- c("weight_joint", "weight_rake")

## Note, only rake weight results reported in paper

lapply(1:length(outcome_vector), function(i)
  lapply(weight_names, function(j)
    
    ### Panel A: Average Treatment Effect ----
    
    table_function(
      data_frames = list(
        diplomacy_long,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide
      ),
      outcomes = c(
        "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[i]),
        "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[i]),
        "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[i]),
        "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[i]),
        "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[i]),
        "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[i])
      ),
      treatments = c(
        "Treated" = "treat_rank", 
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank"
      ),
      trust_covariates = c(
        "country_pre_trust",
        "trust_china_end_pre",
        "trust_india_end_pre",
        "trust_russia_end_pre",
        "trust_uk_end_pre",
        "trust_us_end_pre"
      ),
      fixed_effects_name = "exp_block",
      weights_name = paste0(j),
      table_name = paste0("results_experimental_ATE_", j, "_", names(outcome_vector[i]))
    )
  ))

### Panels B-D ----

het_effects_list <- list(c("rev_rank_reported_ties",
                           "rev_rank_doses_ties_china",
                           "rev_rank_doses_ties_india",
                           "rev_rank_doses_ties_russia",
                           "rev_rank_doses_ties_uk",
                           "rev_rank_doses_ties_us"),
                         c("percentage_reported",
                           "vax_china",
                           "vax_india",
                           "vax_russia",
                           "vax_uk",
                           "vax_us"),
                         c("actual_gte_prior",
                           "actual_gte_prior_china",
                           "actual_gte_prior_india",
                           "actual_gte_prior_russia",
                           "actual_gte_prior_uk",
                           "actual_gte_prior_us"))

names(het_effects_list) <- c("rank", "share", "actgteprior")

het_effects_list_names <- list("Reversed rank", "Share", "Reversed rank $\\geq$ Reversed prior")

lapply(1:length(outcome_vector), function(i)
  lapply(1:length(het_effects_list), function(j)
    lapply(weight_names, function(k)
      
      table_function(
        data_frames = list(
          diplomacy_long,
          diplomacy_wide,
          diplomacy_wide,
          diplomacy_wide,
          diplomacy_wide,
          diplomacy_wide
        ),
        outcomes = c(
          "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[i]),
          "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[i]),
          "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[i]),
          "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[i]),
          "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[i]),
          "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[i])
        ),
        treatments = c(
          "Treated" = "treat_rank", 
          "Treated" = "treat_rank",
          "Treated" = "treat_rank",
          "Treated" = "treat_rank",
          "Treated" = "treat_rank",
          "Treated" = "treat_rank"
        ),
        trust_covariates = c(
          "country_pre_trust",
          "trust_china_end_pre",
          "trust_india_end_pre",
          "trust_russia_end_pre",
          "trust_uk_end_pre",
          "trust_us_end_pre"
        ),
        interaction_effects = list(het_effects_list[[j]]),
        interaction_effects_name = list(het_effects_list_names[[j]]),
        fixed_effects_name = "exp_block",
        weights_name = paste0(k),
        table_name = paste0("results_experimental_", names(het_effects_list)[j], "_", names(outcome_vector[i]), "_", k))
    )
  )
)

lapply(1:length(outcome_vector), function(i)
  lapply(weight_names, function(j)
    
    ### Panel E: Heterogeneity by rank of vaccines received by the respondent's country and prior beliefs ----
    
    table_function(
      data_frames = list(
        diplomacy_long,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide,
        diplomacy_wide
      ),
      outcomes = c(
        "Trust (Pooled)"        = paste0("country_post_trust",    outcome_vector[i]),
        "Trust (China)"         = paste0("trust_china_end_post",  outcome_vector[i]),
        "Trust (India)"         = paste0("trust_india_end_post",  outcome_vector[i]),
        "Trust (Russia)"        = paste0("trust_russia_end_post", outcome_vector[i]),
        "Trust (UK)"            = paste0("trust_uk_end_post",     outcome_vector[i]),
        "Trust (US)"            = paste0("trust_us_end_post",     outcome_vector[i])
      ),
      treatments = c(
        "Treated" = "treat_rank", 
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank",
        "Treated" = "treat_rank"
      ),
      trust_covariates = c(
        "country_pre_trust",
        "trust_china_end_pre",
        "trust_india_end_pre",
        "trust_russia_end_pre",
        "trust_uk_end_pre",
        "trust_us_end_pre"
      ),
      interaction_effects = list(
        c("rev_rank_reported_ties",
          "rev_rank_doses_ties_china",
          "rev_rank_doses_ties_india",
          "rev_rank_doses_ties_russia",
          "rev_rank_doses_ties_uk",
          "rev_rank_doses_ties_us"),
        c("rev_rank_prior",
          "rev_prior_beliefs_china",
          "rev_prior_beliefs_india",
          "rev_prior_beliefs_russia",
          "rev_prior_beliefs_uk",
          "rev_prior_beliefs_us")  
      ),
      interaction_effects_name = list("Reversed Rank", "Reversed prior"),
      fixed_effects_name = "exp_block",
      table_name = paste0("results_experimental_rankprior_", j, "_", names(outcome_vector[i]))
    )
  ))

# A14: The pooled effect of aggregate vaccine distribution information treatment on trust in foreign governments across public good-oriented and cynical respondents, binary outcome ----

## Note: created in tables_experimental.R